package com.szcinda.call;

import com.szcinda.call.repository.Mission;
import com.szcinda.call.service.MissionService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"mission"})
public class MissionController {

    private final MissionService missionService;

    public MissionController(MissionService missionService) {
        this.missionService = missionService;
    }

    @PostMapping("addMission")
    public Result<String> adMission(@RequestBody Mission mission) {
        return Result.success(missionService.addMission(mission));
    }

    @GetMapping("deleteMission/{userName}/{missionId}")
    public Result<String> deleteMission(@PathVariable String userName, @PathVariable String missionId) {
        missionService.deleteMission(userName, missionId);
        return Result.success();
    }

    @GetMapping("finishMission/{userName}/{missionId}")
    public Result<String> finishMission(@PathVariable String userName, @PathVariable String missionId) {
        missionService.finishMission(userName, missionId);
        return Result.success();
    }

    @GetMapping("missionError/{userName}/{missionId}")
    public Result<String> missionError(@PathVariable String userName, @PathVariable String missionId) {
        missionService.missionError(userName, missionId);
        return Result.success();
    }

    @GetMapping("startMission/{userName}/{missionId}")
    public Result<String> startMission(@PathVariable String userName, @PathVariable String missionId) {
        missionService.startMission(userName, missionId);
        return Result.success();
    }

    @GetMapping("getOneMission/{userName}")
    public Result<Mission> getOneMission(@PathVariable String userName) {
        return Result.success(missionService.findOneMission(userName));
    }

    @GetMapping("getMissionById/{userName}/{id}")
    public Result<Mission> getMissionById(@PathVariable String userName, @PathVariable String id) {
        return Result.success(missionService.findMissionById(userName, id));
    }

    @GetMapping("getCurrencyMissions/{userName}")
    public Result<List<Mission>> getCurrencyMissions(@PathVariable String userName) {
        return Result.success(missionService.findMyMission(userName));
    }


    @GetMapping("findHistoryMissions/{userName}")
    public Result<List<Mission>> findHistoryMissions(@PathVariable String userName) {
        return Result.success(missionService.findHistoryMissions(userName));
    }


}
